package com.example.ceshi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.ceshi.Bean.DataDetail;
import com.example.ceshi.Bean.DetailBean;
import com.example.ceshi.R;

import org.w3c.dom.Text;

import java.util.List;

public class DetailAdapter extends BaseAdapter {
    private List<DataDetail> mBeanList;
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public DetailAdapter(Context context, List<DataDetail> beanList) {
        this.mContext = context;
        this.mBeanList = beanList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public int getCount() {
        return mBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return mBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup parent) {
        ViewHolder viewHolder=new ViewHolder();

        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.list_item, parent, false);

            ImageView imageView = view.findViewById(R.id.iv_item);
            TextView text_status = view.findViewById(R.id.tv_status);
            TextView text_content = view.findViewById(R.id.tv_content);
            TextView text_detail = view.findViewById(R.id.tv_detail);

            viewHolder.imageView=imageView;
            viewHolder.text_detail=text_detail;
            viewHolder.text_status=text_status;
            viewHolder.text_content=text_content;

            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }





        DataDetail dataDetail = mBeanList.get(i);

//        imageView.setImageResource();
//        配置图片信息
        switch (dataDetail.getExpressCode()) {
            case "SF":
                viewHolder.imageView.setImageResource(R.drawable.sf);
                break;
            case "YTO":
                viewHolder.imageView.setImageResource(R.drawable.yuantong);
                break;
            case "ZTO":
                viewHolder.imageView.setImageResource(R.drawable.zhongtong);
                break;
            case "YUNDA":
                viewHolder.imageView.setImageResource(R.drawable.yunda);
                break;
            case "STO":
                viewHolder.imageView.setImageResource(R.drawable.shentong);
                break;
            case "TTKDEX":
                viewHolder.imageView.setImageResource(R.drawable.tiantian);
                break;
            case "JD":
                viewHolder.imageView.setImageResource(R.drawable.jingdong);
                break;
            case "EMS":
                viewHolder.imageView.setImageResource(R.drawable.youzheng);
                break;
            case "DBKD":
                viewHolder.imageView.setImageResource(R.drawable.debang);
                break;
            case "DBL":
                viewHolder.imageView.setImageResource(R.drawable.debang);
                break;
            case "DBKY":
                viewHolder.imageView.setImageResource(R.drawable.debang);
                break;
            case "JT":
                viewHolder.imageView.setImageResource(R.drawable.jitu);
                break;
            default:
                viewHolder.imageView.setImageResource(R.drawable.ic_notfound);
                break;
        }
//        配置状态信息
        viewHolder.text_status.setText(dataDetail.getLogisticsStatusDesc());
//        配置cotent内容
        viewHolder.text_content.setText("上次更新：" + dataDetail.getTheLastTime());
//        配置详细信息
        viewHolder.text_detail.setText(dataDetail.getExpressCompanyName() + " | " + dataDetail.getNumber());

        return view;
    }

    class ViewHolder {
        ImageView imageView;
        TextView text_status;
        TextView text_content;
        TextView text_detail;
    }
}
